﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Windows.Forms;
using System.IO;

namespace RiotTweet
{
    public static class AppUtil
    {
        public static string AppTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length == 0)
                {
                    return null;
                }
                AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                return titleAttribute.Title;
            }
        }

        public static string DebugTitle
        {
            get
            {
#if DEBUG
                return " [DEBUG]";
#else
                return "";
#endif
            }
        }

        public static void ShowError(string message)
        {
            MessageBox.Show(message, AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static void ErrorLog(string message)
        {
            string logPath = Application.ExecutablePath + ".log";
            using (StreamWriter writer = File.AppendText(logPath))
            {
                writer.WriteLine(message);
            }
        }

        public static void ErrorLog(string message, Exception ex)
        {
            if (ex == null)
            {
                ex = new Exception();
            }
            System.Diagnostics.Debug.WriteLine(ex);
            ErrorLog(ex.Message + "\r\n" + ex.StackTrace);
        }

    
    }
}
